home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / OS2 / GG243774.ARJ / DROPINFO.C < prev    next >
Text File  |  1992-04-10  |  15KB  |  345 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  PROGRAM NAME:  DROPINFO                                                  */
  4. /*                                                                           */
  5. /*  PURPOSE:       This program provides information for testing and         */
  6. /*                 debugging drag-and-drop applications.  When an object is  */
  7. /*                 dropped over this program's window, the window shows the  */
  8. /*                 information received from the source.                     */
  9. /*                                                                           */
  10. /*****************************************************************************/
  11.  
  12. #define INCL_WIN
  13. #define INCL_GPI
  14.  
  15. #define INCL_WINSTDDRAG
  16. #include <os2.h>                                 /* PM header file           */
  17. #include "dropinfo.h"                            /* Application header file  */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22.  
  23. /*****************************************************************************/
  24. /* Window procedure prototypes                                               */
  25. /*****************************************************************************/
  26. MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  27. MRESULT EXPENTRY wpSubList( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  28.  
  29. /*****************************************************************************/
  30. /* Function prototypes                                                       */
  31. /*****************************************************************************/
  32. void PutMsg(HWND hwnd, char *type, MPARAM mp1, MPARAM mp2);
  33. void PutDInfo(HWND hwnd, PDRAGINFO pdinfo);
  34. void PutDItem(HWND hwnd, PDRAGITEM pditem);
  35.  
  36. /*****************************************************************************/
  37. /* Global data                                                               */
  38. /*****************************************************************************/
  39. HAB  hAB;                                        /* Anchor block handle      */
  40. PFNWP pwpList;                                   /* Listbox winproc address  */
  41.  
  42. /*****************************************************************************/
  43. /* Application main routine                                                  */
  44. /*****************************************************************************/
  45. INT main (VOID)
  46. {
  47.   HMQ  hMsgQ;                                    /* Message queue handle     */
  48.   QMSG qMsg;                                     /* Message structure        */
  49.   HWND hFrame;                                   /* Frame window handle      */
  50.  
  51.   ULONG flCreate = FCF_STANDARD & ~FCF_MENU;     /* Frame creation flags     */
  52.  
  53.   ULONG rc;                                      /* Return code              */
  54.  
  55.   hAB = WinInitialize(0);                        /* Register application     */
  56.  
  57.   hMsgQ = WinCreateMsgQueue(hAB, 0);             /* Create message queue     */
  58.  
  59.   rc = WinRegisterClass(hAB,                     /* Register window class    */
  60.                         (PSZ)"MyWindow",         /* Class name               */
  61.                         (PFNWP)MyWindowProc,     /* Window procedure address */
  62.                         CS_SIZEREDRAW,           /* Class style              */
  63.                         sizeof(PVOID));          /* Window words             */
  64.  
  65.   hFrame = WinCreateStdWindow(HWND_DESKTOP,      /* Desktop is parent        */
  66.                               0,                 /* Standard window style    */
  67.                               &flCreate,         /* Frame control flags      */
  68.                               "MyWindow",        /* Window class name        */
  69.                               "DropInfo Sample", /* Window title text        */
  70.                               0,                 /* No special class style   */
  71.                               (HMODULE)0L,       /* Resources in EXE file    */
  72.                               ID_WINDOW,         /* Frame window identifier  */
  73.                               NULL);             /* No pres params           */
  74.  
  75.   while (WinGetMsg(hAB, &qMsg, 0L, 0, 0))        /* Process messages until   */
  76.         WinDispatchMsg(hAB, &qMsg);              /* WM_QUIT received         */
  77.  
  78.   WinDestroyWindow(hFrame);                      /* Destroy window           */
  79.   WinDestroyMsgQueue(hMsgQ);                     /* Destroy message queue    */
  80.   WinTerminate(hAB);                             /* Deregister application   */
  81. }
  82.  
  83. /*****************************************************************************/
  84. /* Main window procedure                                                     */
  85. /*****************************************************************************/
  86. MRESULT EXPENTRY MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  87. {
  88.   SWP   swp;
  89.   ULONG rc;
  90.  
  91.   HWND  hFrame;
  92.   HWND  hListBox;                                /* Listbox window handle    */
  93.  
  94.   switch (msg)
  95.          {
  96.          case WM_CREATE:
  97.               hListBox = WinCreateWindow(hwnd,
  98.                                          WC_LISTBOX,
  99.                                          NULL,
  100.                                          WS_VISIBLE     |
  101.                                          LS_NOADJUSTPOS |
  102.                                          LS_HORZSCROLL,
  103.                                          0, 0, 0, 0,
  104.                                          hwnd,
  105.                                          HWND_TOP,
  106.                                          ID_LISTBOX,
  107.                                          0,
  108.                                          0);
  109.  
  110.               pwpList = WinSubclassWindow(hListBox,
  111.                            wpSubList);
  112.  
  113.               hFrame = WinQueryWindow(hwnd,
  114.                                       QW_PARENT);
  115.               rc = WinSetWindowPos(hFrame,
  116.                                    HWND_TOP,
  117.                                    0, 0,
  118.                                    400, 300,
  119.                                    SWP_SIZE     |
  120.                                    SWP_ACTIVATE |
  121.                                    SWP_SHOW);
  122.               break;
  123.  
  124.          case WM_SIZE:
  125.               WinQueryWindowPos(hwnd, &swp);
  126.               hListBox=WinWindowFromID(hwnd,
  127.                                        ID_LISTBOX);
  128.               WinSetWindowPos(hListBox,
  129.                               HWND_TOP,
  130.                               swp.x, swp.y,
  131.                               swp.cx, swp.cy,
  132.                               SWP_SIZE  |
  133.                               SWP_SHOW);
  134.               break;
  135.  
  136.          default:
  137.               return(WinDefWindowProc(hwnd,
  138.                                       msg,
  139.                                       mp1,
  140.                                       mp2));
  141.          }
  142.   return((MRESULT)FALSE);
  143. }
  144.  
  145. /*****************************************************************************/
  146. /* Listbox subclass window procedure                                         */
  147. /*****************************************************************************/
  148. MRESULT EXPENTRY wpSubList(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  149. {
  150.   PDRAGINFO pDInfo;                              /* Pointer to DRAGINFO      */
  151.   PDRAGITEM pDItem;                              /* Pointer to DRAGITEM      */
  152.   ULONG rc;                                      /* Return code              */
  153.   int i;                                         /* Loop counter             */
  154.  
  155.   switch (msg)
  156.          {
  157.          case DM_DRAGOVER:
  158.               pDInfo = (PDRAGINFO)mp1;
  159.               rc = DrgAccessDragInfo(pDInfo);
  160.               pDItem = DrgQueryDragitemPtr(pDInfo, 0);
  161.               return(MPFROM2SHORT(DOR_DROP,      /* Drop Allowed             */
  162.                                   DO_UNKNOWN));
  163.               break;
  164.  
  165.          case DM_DROP:                           /* Object being dropped     */
  166.               PutMsg(hwnd,"DM_DROP",mp1,mp2);    /* Put message in listbox   */
  167.               pDInfo = (PDRAGINFO)mp1;           /* Extract DRAGINFO pointer */
  168.               rc =DrgAccessDragInfo(pDInfo);     /* Access DRAGINFO data     */
  169.               PutDInfo(hwnd, pDInfo);            /* Put DRAGINFO in listbox  */
  170.  
  171.               pDItem = DrgQueryDragitemPtr(pDInfo, 0); /* Get DRAGITEMs      */
  172.  
  173.               for (i=0; i < pDInfo->cditem; i++) /* For each DRAGITEM        */
  174.                   {
  175.                   PutDItem(hwnd, pDItem++);      /* Put DRAGITEM in listbox  */
  176.                   }
  177.               break;
  178.  
  179.          default:                                /* All other messages       */
  180.               return((MRESULT)pwpList(hwnd,      /* Invoke default listbox   */
  181.                                       msg,       /* window procedure         */
  182.                                       mp1,
  183.                                       mp2));
  184.               break;
  185.          }
  186. }
  187.  
  188. /*****************************************************************************/
  189. /* Put message info in listbox item                                          */
  190. /*****************************************************************************/
  191. void PutMsg(HWND hwnd, char *type, MPARAM mp1, MPARAM mp2)
  192. {
  193.   char buf[100];                                 /* Message buffer           */
  194.  
  195.   sprintf(buf,                                   /* Copy info to buffer      */
  196.           "%s %08X, %08x",
  197.           type,
  198.           mp1,
  199.           mp2);
  200.   WinSendMsg(hwnd,                               /* Set listbox top index    */
  201.              LM_SETTOPINDEX,
  202.              (MPARAM)WinSendMsg(hwnd,            /* Position of new item     */
  203.                                 LM_INSERTITEM,
  204.                                 (MPARAM)LIT_END,
  205.                                 MPFROMP(buf)),
  206.              NULL);
  207.   return;
  208. }
  209.  
  210. /*****************************************************************************/
  211. /* Put DRAGINFO structure contents in listbox item                           */
  212. /*****************************************************************************/
  213. void PutDInfo(HWND hwnd, PDRAGINFO pDInfo)
  214. {
  215.   char buf[500];                                 /* Buffer                   */
  216.   sprintf(buf,                                   /* Copy info to buffer      */
  217.           "   DRAGINFO: size: %d(DragInfo), %d(DragItem), \n   ---Ops: %d, hwndSource: %08X, drop coords: (%d, %d), cdItem cnt: %d",
  218.           pDInfo->cbDraginfo,
  219.           pDInfo->cbDragitem,
  220.           pDInfo->usOperation,
  221.           pDInfo->hwndSource,
  222.           pDInfo->xDrop,
  223.           pDInfo->yDrop,
  224.           pDInfo->cditem);
  225.  
  226.   WinSendMsg(hwnd,                               /* Set listbox top index    */
  227.              LM_SETTOPINDEX,
  228.              (MPARAM)WinSendMsg(hwnd,            /* Position of new item     */
  229.                                 LM_INSERTITEM,
  230.                                 (MPARAM)LIT_END,
  231.                                 MPFROMP(buf)),
  232.              NULL);
  233.   return;
  234. }
  235.  
  236. /*****************************************************************************/
  237. /* Put DRAGITEM structure contents in listbox item                           */
  238. /*****************************************************************************/
  239. void PutDItem(HWND hwnd, PDRAGITEM pDItem)
  240. {
  241.   char buf[500],                                 /* Buffers                  */
  242.        srceType[100],
  243.        srceContainer[100],
  244.        srceName[100],
  245.        srceRMF[100],
  246.        targetName[100];
  247.  
  248.   DrgQueryStrName(pDItem->hstrSourceName,        /* Get info from DRAGITEM   */
  249.                   100,
  250.                   srceName);
  251.   DrgQueryStrName(pDItem->hstrContainerName,
  252.                   100,
  253.                   srceContainer);
  254.   DrgQueryStrName(pDItem->hstrType,
  255.                   100,
  256.                   srceType);
  257.   DrgQueryStrName(pDItem->hstrRMF,
  258.                   100,
  259.                   srceRMF);
  260.   DrgQueryStrName(pDItem->hstrTargetName,
  261.                   100,
  262.                   targetName);
  263.  
  264.   sprintf(buf,                                   /* Copy info to buffer      */
  265.           "   DRAGITEM: ulItemID: %d",
  266.           pDItem->ulItemID);
  267.   WinSendMsg(hwnd,                               /* Set listbox top index    */
  268.              LM_SETTOPINDEX,
  269.              (MPARAM)WinSendMsg(hwnd,            /* Position of new item     */
  270.                                 LM_INSERTITEM,
  271.                                 (MPARAM)LIT_END,
  272.                                 MPFROMP(buf)),
  273.              NULL);
  274.  
  275.   sprintf(buf,
  276.           "   --Type:      \"%s\"",
  277.           srceType);
  278.   WinSendMsg(hwnd,
  279.              LM_SETTOPINDEX,
  280.              (MPARAM)WinSendMsg(hwnd,
  281.                                 LM_INSERTITEM,
  282.                                 (MPARAM)LIT_END,
  283.                                 MPFROMP(buf)),
  284.              NULL);
  285.  
  286.   sprintf(buf,
  287.           "   --RMF:       \"%s\"",
  288.           srceRMF);
  289.   WinSendMsg(hwnd,
  290.              LM_SETTOPINDEX,
  291.              (MPARAM)WinSendMsg(hwnd,
  292.                                 LM_INSERTITEM,
  293.                                 (MPARAM)LIT_END,
  294.                                 MPFROMP(buf)),
  295.              NULL);
  296.  
  297.   sprintf(buf,
  298.           "   --Container: \"%s\"",
  299.           srceContainer);
  300.   WinSendMsg(hwnd,
  301.              LM_SETTOPINDEX,
  302.              (MPARAM)WinSendMsg(hwnd,
  303.                                 LM_INSERTITEM,
  304.                                 (MPARAM)LIT_END,
  305.                                 MPFROMP(buf)),
  306.              NULL);
  307.  
  308.   sprintf(buf,
  309.           "   --SourceName:      \"%s\"",
  310.           srceName);
  311.   WinSendMsg(hwnd,
  312.              LM_SETTOPINDEX,
  313.              (MPARAM)WinSendMsg(hwnd,
  314.                                 LM_INSERTITEM,
  315.                                 (MPARAM)LIT_END,
  316.                                 MPFROMP(buf)),
  317.              NULL);
  318.  
  319.   sprintf(buf,
  320.           "   --TargetName:      \"%s\"",
  321.           targetName);
  322.   WinSendMsg(hwnd,
  323.              LM_SETTOPINDEX,
  324.              (MPARAM)WinSendMsg(hwnd,
  325.                                 LM_INSERTITEM,
  326.                                 (MPARAM)LIT_END,
  327.                                 MPFROMP(buf)),
  328.              NULL);
  329.  
  330.   sprintf(buf,
  331.           "   --Offset: (%d, %d), cntl: %d, ops: %d",
  332.           pDItem->cxOffset,
  333.           pDItem->cyOffset,
  334.           pDItem->fsControl,
  335.           pDItem->fsSupportedOps);
  336.   WinSendMsg(hwnd,
  337.              LM_SETTOPINDEX,
  338.              (MPARAM)WinSendMsg(hwnd,
  339.                                 LM_INSERTITEM,
  340.                                 (MPARAM)LIT_END,
  341.                                 MPFROMP(buf)),
  342.              NULL);
  343.   return;
  344. }
  345.